<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: admusernew.php,v $ 
 * $Date: 2006/03/21 17:28:33 $ 
 * $Revision: 1.3 $ 
 * 
 * ********* CVS HEADER ********* 
 */
require_once ("module/TPLN/TPLN.php");
$TPLN = new TPLN;

$TPLN -> Open($op_basepath."tpl/admusernew.html");
$TPLN -> IncludeFile("header", "environnement/".$session["environnement"]."/header.php");
$TPLN -> IncludeFile("footer", "environnement/".$session["environnement"]."/footer.php");

require_once(get_path_module("admin")); 
$pc = new panneau_controle(); 
$pc->calculRubriqueParFonction($op); 
$TPLN->Parse("panneau_controle",$pc->retourneEntete());

$erreur=0;
$L_bloc = "confirm_mail";
if($confirm==1) {
	$groupdefseq = $rportalparams->get_value("RPORTAL","groupe.sequenceur");
	$query ="SELECT id FROM utilisateur WHERE login='$new_login'";
	$query.=" OR (nom='$new_nom' AND prenom='$new_prenom' AND email='$new_mail')";
	$result=rportalrequete($query) or die ("ERREUR 0076");
	if($row=rportalligne($result)) {
		$erreur=1;
	} else {
		require_once(get_path_module("password.password"));
		$pwd = getRandomPassword(8);
		$L_pwd = $pwd;
		$pwd=md5("$L_pwd");
		$query ="INSERT INTO utilisateur (login,nom,prenom,email,password,id_groupe)";
		$query.=" VALUES ('$new_login','$new_nom','$new_prenom','$new_mail','$pwd','$groupdefseq')";
		$res=@rportalrequete($query) or die ("ERREUR 0076");
		$argid=rportallastid($res);
		$inscdefseq=$rportalparams->get_value("RPORTAL","sequence.inscription");
		$query="SELECT id FROM sequence_ordre WHERE id_sequence='$inscdefseq' ORDER BY id";
		$result2=rportalrequete($query) or die ("ERREUR 0114");
		$etape=-1;
		if($row2=rportalligne($result2)) {
			$etape=$row2["id"];
		}
		$query ="INSERT INTO sequence_status (login,id_groupe,etape,id_sequence)";
		$query.=" VALUES ('$new_login','$new_groupe','$etape','$inscdefseq')";
		$result=rportalrequete($query) or die ("ERREUR 0115");
		
		
		require_once(get_path_module("email.emailtype"));
		$email = new emailtype($rportalparams->get_value("RPORTAL","email.compte.creation"));
		$email->setFrom($rportalparams->get_value("SITE","webmaster.nom"),$rportalparams->get_value("SITE","webmaster.email"));
		$email->setTo($new_mail,$new_login,$new_nom,$new_prenom,$L_pwd);
		
		$L_message = nl2br($email->getMessage());
		if(trim($rportalparams->get_value("RPORTAL","email.actif"))=="yes" && $new_mail!='')
		{
			$email->sendEmail();
			$L_texte = "Message electronique envoye:";
		}
		else
		{
			$L_texte = "Message electronique a envoyer a: ".$new_mail;
		}
		
		$TPLN -> Parse($L_bloc.".texte", $L_texte);
		$TPLN -> Parse($L_bloc.".message", $L_message);
		$TPLN -> EraseBloc("nouvel_utilisateur");
		$TPLN->Write();
		exit();
	}
} else {
	$TPLN -> EraseBloc($L_bloc);
}

$L_bloc = "nouvel_utilisateur";

if($erreur==1) {
	$TPLN -> Parse($L_bloc.".information", "le profil existe d&eacute;j&agrave;<br>");
	$TPLN -> EraseBloc("confirm_mail");
} else {
	$TPLN -> EraseItem($L_bloc.".information");
}
$query="SELECT * from groupe GROUP BY id";
$result=rportalrequete($query) or die ("ERREUR 0076");
$L_subbloc = $L_bloc.".groupes";
$L_nbElem = 0;
while($row=rportalligne($result)) {
	$TPLN -> Parse($L_subbloc.".id", $row["id"]);
	$TPLN -> Parse($L_subbloc.".nom", $row["nom"]);
	$L_nbElem++;
	$TPLN -> Loop($L_subbloc);	
}
if (0==$L_nbElem) {
	/* No line, erase bloc */
	$TPLN -> EraseBloc($L_subbloc);
}
$TPLN->Write();

?>